﻿package lobby
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import lobby.events.LobbyEvent;
	import lobby.exchangeddata.HashTable;
	
	/**
	 * ...
	 * @author Nguyen Hoang Giang (Tom)
	 */
	public class HistoryPanelBaccarat extends HistoryPanelBase
	{
		private static const BANKER:String = "10";
		private static const BANKER_P:String = "11";
		private static const BANKER_PP:String = "12";
		private static const BANKER_BPP:String = "13";
		
		private static const PLAYER:String = "20";
		private static const PLAYER_BP:String = "21";
		private static const PLAYER_P:String = "22";
		private static const PLAYER_BPP:String = "23";
		
		private static const TIE:String = "30";
		private static const TIE_BP:String = "31";
		private static const TIE_PP:String = "32";
		private static const TIE_BPP:String = "33";
		
		public override function initBoard(resultArr:Array):void
		{
			removeHistory();
			if (resultArr.length == 0)
				return;
			
			var i:int;
			if (resultArr.length > MAX_NUM_CHECKERS)
			{
				i = Math.abs(resultArr.length - MAX_NUM_CHECKERS - rowNum - 1);
			}
			for (i; i < resultArr.length; i++)
			{
				//drawIcon(resultArr[i]);
				var iconHis:MovieClip = attachIcon(resultArr[i]);
				iconHis.name = (i + 1).toString();
				//trace(iconHis.name);
				if (rowInd + 1 == rowNum)
				{
					rowInd = 0;
					colInd++;
				}
				else
					rowInd++;
			}
		
		}
		
		public override function attachIcon(type:String):MovieClip
		{
			var hisIcon:MovieClip = MovieClip(new HistoryIconBac());
			var icon:MovieClip = hisIcon.mc;
			hisBoard.addChild(hisIcon);
			hisIcon.x = colInd * 18.5 + 9.25;
			hisIcon.y = rowInd * 18.5 + 9.25;
			//hisIcon.scaleX = hisIcon.scaleY = 0.69;
			icon.bankerPair.visible = false;
			icon.playerPair.visible = false;
			// banker 
			if (type == HistoryPanelBaccarat.BANKER)
			{
				icon.gotoAndStop("banker");
				if (GlobalVariables.lang == "G" || GlobalVariables.lang == "B")
				{
					icon.banker_mc.gotoAndStop("G");
				}
				else
				{
					icon.banker_mc.gotoAndStop("E");
				}
				icon.banker_mc.visible = true;
				return hisIcon;
			}
			if (type == HistoryPanelBaccarat.BANKER_P)
			{
				icon.gotoAndStop("banker");
				icon.bankerPair.visible = true;
				if (GlobalVariables.lang == "G" || GlobalVariables.lang == "B")
				{
					icon.banker_mc.gotoAndStop("G");
				}
				else
				{
					icon.banker_mc.gotoAndStop("E");
				}
				icon.banker_mc.visible = true;
				return hisIcon;
			}
			if (type == HistoryPanelBaccarat.BANKER_PP)
			{
				icon.gotoAndStop("banker");
				icon.playerPair.visible = true;
				if (GlobalVariables.lang == "G" || GlobalVariables.lang == "B")
				{
					icon.banker_mc.gotoAndStop("G");
				}
				else
				{
					icon.banker_mc.gotoAndStop("E");
				}
				icon.banker_mc.visible = true;
				return hisIcon;
			}
			if (type == HistoryPanelBaccarat.BANKER_BPP)
			{
				icon.gotoAndStop("banker");
				icon.bankerPair.visible = true;
				icon.playerPair.visible = true;
				if (GlobalVariables.lang == "G" || GlobalVariables.lang == "B")
				{
					icon.banker_mc.gotoAndStop("G");
				}
				else
				{
					icon.banker_mc.gotoAndStop("E");
				}
				icon.banker_mc.visible = true;
				return hisIcon;
			}
			
			// player 
			if (type == HistoryPanelBaccarat.PLAYER)
			{
				icon.gotoAndStop("player");
				if (GlobalVariables.lang == "G" || GlobalVariables.lang == "B")
				{
					icon.player_mc.gotoAndStop("G");
				}
				else
				{
					icon.player_mc.gotoAndStop("E");
				}
				icon.player_mc.visible = true;
				return hisIcon;
			}
			if (type == HistoryPanelBaccarat.PLAYER_P)
			{
				icon.gotoAndStop("player");
				icon.playerPair.visible = true;
				if (GlobalVariables.lang == "G" || GlobalVariables.lang == "B")
				{
					icon.player_mc.gotoAndStop("G");
				}
				else
				{
					icon.player_mc.gotoAndStop("E");
				}
				icon.player_mc.visible = true;
				return hisIcon;
			}
			if (type == HistoryPanelBaccarat.PLAYER_BP)
			{
				icon.gotoAndStop("player");
				icon.bankerPair.visible = true;
				if (GlobalVariables.lang == "G" || GlobalVariables.lang == "B")
				{
					icon.player_mc.gotoAndStop("G");
				}
				else
				{
					icon.player_mc.gotoAndStop("E");
				}
				icon.player_mc.visible = true;
				return hisIcon;
			}
			if (type == HistoryPanelBaccarat.PLAYER_BPP)
			{
				icon.gotoAndStop("player");
				icon.bankerPair.visible = true;
				icon.playerPair.visible = true;
				if (GlobalVariables.lang == "G" || GlobalVariables.lang == "B")
				{
					icon.player_mc.gotoAndStop("G");
				}
				else
				{
					icon.player_mc.gotoAndStop("E");
				}
				icon.player_mc.visible = true;
				return hisIcon;
			}
			
			// tie
			if (type == HistoryPanelBaccarat.TIE)
			{
				icon.gotoAndStop("tie");
				if (GlobalVariables.lang == "G" || GlobalVariables.lang == "B")
				{
					icon.tie_mc.gotoAndStop("G");
				}
				else
				{
					icon.tie_mc.gotoAndStop("E");
				}
				icon.tie_mc.visible = true;
				return hisIcon;
			}
			if (type == HistoryPanelBaccarat.TIE_BP)
			{
				icon.gotoAndStop("tie");
				icon.bankerPair.visible = true;
				if (GlobalVariables.lang == "G" || GlobalVariables.lang == "B")
				{
					icon.tie_mc.gotoAndStop("G");
				}
				else
				{
					icon.tie_mc.gotoAndStop("E");
				}
				icon.tie_mc.visible = true;
				return hisIcon;
			}
			if (type == HistoryPanelBaccarat.TIE_PP)
			{
				icon.gotoAndStop("tie");
				icon.playerPair.visible = true;
				if (GlobalVariables.lang == "G" || GlobalVariables.lang == "B")
				{
					icon.tie_mc.gotoAndStop("G");
				}
				else
				{
					icon.tie_mc.gotoAndStop("E");
				}
				icon.tie_mc.visible = true;
				return hisIcon;
			}
			if (type == HistoryPanelBaccarat.TIE_BPP)
			{
				icon.gotoAndStop("tie");
				icon.bankerPair.visible = true;
				icon.playerPair.visible = true;
				if (GlobalVariables.lang == "G" || GlobalVariables.lang == "B")
				{
					icon.tie_mc.gotoAndStop("G");
				}
				else
				{
					icon.tie_mc.gotoAndStop("E");
				}
				icon.tie_mc.visible = true;
				return hisIcon;
			}
			return null;
		}
		
		private function removeIterm(boad:Sprite, nameIterm:String):void
		{
			var obj:DisplayObject = boad.getChildByName(nameIterm);
			if (obj != null)
				boad.removeChild(obj);
		}
		
		public function askBankerPlayer(num:String, sLoop:String)
		{
			if (sLoop != "N")
			{
				removeIterm(hisBoard, "ask");
				var iconHis:MovieClip = attachIcon(num);
				iconHis.name = "ask";
				iconHis.gotoAndPlay("loop");
			}
		}
		
	}

}